package proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import lombok.Data;

@Data
public class LogHandler implements InvocationHandler {
    private final Object target;

    public LogHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String methodName = method.getName();
        System.out.println("============================");
        System.out.println("开始执行方法: " + methodName + " 时间: " + LocalDateTime.now());
        
        // 执行目标方法
        Object result = method.invoke(target, args);
        
        System.out.println("方法执行完成: " + methodName + " 时间: " + LocalDateTime.now());
        System.out.println("============================");
        return result;
    }
} 